import { useIntersectionObserver } from '@vueuse/core'
import { ref } from 'vue'
export const userLazyData = api => {
  const target = ref(null)
  const result = ref([])
  const { stop } = useIntersectionObserver(
    target,
    ([{ isIntersecting }]) => {
      if (isIntersecting) {
        api().then(data => {
          result.value = data.result
        })
        stop()
      }
    },
    { threshold: 0.1 }
  )
  return { result, target }
}
